package com.trkj.utils;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class OverallSituationInterceptor extends HandlerInterceptorAdapter {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		HttpSession session = request.getSession();
		if (handler.getClass() == HandlerMethod.class) {
			HandlerMethod handlerMethod = (HandlerMethod) handler;
			Method method = handlerMethod.getMethod();
			if (method.getName().equals("login")) {
				System.out.println("放行");
				return true;
			}
			if (session.getAttribute("emp") != null) {
				System.out.println("放行");
				return true;
			} else {
				System.out.println("拦截");
				response.sendRedirect("to_login");
				return false;
			}
		}
		return true;

	}
}
